#!/bin/bash -e
# 
# File: check-ip.sh
# Purpose: check ip
#

IPADDR=$1
ERROR=1
if [ -n "$IPADDR" ] ; then
    regex="\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\b"
    ckStep2=`echo $1 | egrep $regex | wc -l`
    if [ $ckStep2 -eq 0 ]
    then
       echo "The string $IPADDR is not a correct ipaddr!!!";
       ERROR=1;
    else
       ERROR=0;
    fi
else
    echo 'please enter ip.'
    ERROR=2;
fi
exit $ERROR

